package org.compiere.process;

import java.io.File;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;

import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.Colour;
import jxl.format.VerticalAlignment;
import jxl.write.DateFormat;
import jxl.write.DateTime;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableCellFormat;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

import org.adempiere.exceptions.AdempiereException;
import org.compiere.apps.ADialog;
import org.compiere.model.MAttachmentEntry;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;

import extend.org.compiere.hrm.ExcelCell;
import extend.org.compiere.utils.Util;

public class CMS_FinanceContractReport extends SvrProcess {

	// Current context
	private Properties m_ctx;
	//		
	private ProcessInfo pi;
	//Client
	private int			AD_Client_ID = 0;
	//Organization
	private int			AD_Org_ID = 0;
	//User
	private int 		AD_User_ID = 0;
	//Role
	private int			AD_Role_ID = 0;
	// Business Partner
	private int C_BPartner_ID = 0;
	//Contract Date (start range)
	private Timestamp DateFrom = null;
	//Contract Date (end range)
	private Timestamp DateTo = null;
	
	private static CLogger	s_log	= CLogger.getCLogger (CMS_FinanceContractReport.class);
	
	private String path = "";
	
	@Override
	protected void prepare() {
		log.info("");
		m_ctx = Env.getCtx();
		pi = getProcessInfo();
		ProcessInfoParameter[] para = getParameter();
		
		for(int i = 0; i < para.length; i++) {
			String name = para[i].getParameterName();			
			if (para[i].getParameter() == null);
			else if (name.equals("AD_Client_ID"))
				AD_Client_ID = ((BigDecimal)para[i].getParameter()).intValue();
			else if (name.equals("AD_Org_ID"))
				AD_Org_ID = ((BigDecimal)para[i].getParameter()).intValue();
			else if (name.equals("C_BPartner_ID"))
				C_BPartner_ID = ((BigDecimal)para[i].getParameter()).intValue();
			else if (name.equals("DateFrom"))
				DateFrom = (Timestamp)para[i].getParameter();	
			else if (name.equals("DateTo"))
				DateTo = (Timestamp)para[i].getParameter();
			else if (name.toLowerCase().endsWith("directory"))
				path = (String)para[i].getParameter();
			else
			{
				log.log(Level.SEVERE, "Unknown Parameter: " + name);
			}				
		}
		if(path.isEmpty()){
			path = Util.localFilePath;
		}else
			path = path + System.getProperty("file.separator");
		
		AD_User_ID = Env.getAD_User_ID(getCtx());
		AD_Role_ID = Env.getAD_Role_ID(getCtx());
	}

	int indexNum = 0;
	
	@Override
	protected String doIt() throws Exception {
		String patternName = "pattern_FinContract";
		
		//get attachment FROM the process
		MAttachmentEntry entry = Util.getAttachment(pi, m_ctx, patternName);
		if(entry == null)
			throw new AdempiereException(Msg.translate(m_ctx, "NotFoundTemplate")+" "+patternName);
		
		if(getCMS_Contract_ID() == 0)
			return "Not available for contracts";
		
		// We define a path to generate
		String fileExtension = entry.getName().substring(entry.getName().lastIndexOf("."),entry.getName().length());
		StringBuffer fullPath = new StringBuffer(path);		
		fullPath.append("Temporary CMS Finance Contract Sheets");		
		fullPath.append(fileExtension);
		
		File templateCopy = new File(fullPath.toString());
        File temporaryFile = entry.getFile(Util.localFilePath+patternName);
		Workbook tableBook = null;
		WritableWorkbook copy = null;
		WritableSheet sheet = null;
		
		try {
			tableBook = Workbook.getWorkbook(temporaryFile);
			copy = Workbook.createWorkbook(templateCopy, tableBook);
			sheet = copy.getSheet(0);
        } 
		catch (Exception e) {
        	ADialog.error(999, null, "Error tableBook. " + e.getMessage());
        	return "Error tableBook.";
        }
		
		ExcelCell cellStart =  Util.getCellStart(tableBook,">>");
		
		// Style for value column
		WritableCellFormat nn = new WritableCellFormat();
		nn.setBorder(Border.LEFT, BorderLineStyle.THIN, Colour.BLACK);
		nn.setBorder(Border.RIGHT, BorderLineStyle.THIN, Colour.BLACK);
		nn.setBorder(Border.BOTTOM, BorderLineStyle.THIN, Colour.BLACK);
		nn.setBorder(Border.TOP, BorderLineStyle.THIN, Colour.BLACK);
		nn.setAlignment(Alignment.CENTRE);
		nn.setVerticalAlignment(VerticalAlignment.CENTRE);
		nn.setWrap(true);
	    
		
	    WritableCellFormat valuestyle = new WritableCellFormat();
	    valuestyle.setBorder(Border.LEFT, BorderLineStyle.THIN, Colour.BLACK);
	    valuestyle.setBorder(Border.RIGHT, BorderLineStyle.THIN, Colour.BLACK);
	    valuestyle.setBorder(Border.BOTTOM, BorderLineStyle.THIN, Colour.BLACK);
	    valuestyle.setBorder(Border.TOP, BorderLineStyle.THIN, Colour.BLACK);
	    valuestyle.setAlignment(Alignment.LEFT);
	    valuestyle.setVerticalAlignment(VerticalAlignment.CENTRE);
	    valuestyle.setWrap(true);
	    // Style for name column
	    WritableCellFormat namestyle = new WritableCellFormat();
	    namestyle.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK);
	    namestyle.setAlignment(Alignment.LEFT);
	    namestyle.setVerticalAlignment(VerticalAlignment.CENTRE);
	    namestyle.setWrap(true);
	    //Style for number column
	    WritableCellFormat numcolstyle = new WritableCellFormat();
	    numcolstyle.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK);
	    numcolstyle.setAlignment(Alignment.RIGHT);
	    numcolstyle.setVerticalAlignment(VerticalAlignment.CENTRE);
	    numcolstyle.setWrap(true);
	    //Style for last number column
	    WritableCellFormat lastNumcolstyle = new WritableCellFormat();
	    lastNumcolstyle.setBorder(Border.RIGHT, BorderLineStyle.THIN, Colour.BLACK);
	    lastNumcolstyle.setBorder(Border.LEFT, BorderLineStyle.THIN, Colour.BLACK);
	    lastNumcolstyle.setBorder(Border.TOP, BorderLineStyle.THIN, Colour.BLACK);
	    lastNumcolstyle.setBorder(Border.BOTTOM, BorderLineStyle.THIN, Colour.BLACK);
	    lastNumcolstyle.setAlignment(Alignment.RIGHT);
	    lastNumcolstyle.setVerticalAlignment(VerticalAlignment.CENTRE);
	    lastNumcolstyle.setWrap(true);
	    //Style for total row
	    WritableCellFormat totalrowstyle = new WritableCellFormat();
	    totalrowstyle.setBorder(Border.ALL, BorderLineStyle.MEDIUM, Colour.BLACK);
	    totalrowstyle.setAlignment(Alignment.RIGHT);
	    totalrowstyle.setVerticalAlignment(VerticalAlignment.CENTRE);
	    totalrowstyle.setWrap(true);

	    DateFormat customDateFormat = new DateFormat ("dd.MM.yy");
	    WritableCellFormat dateFormat = new WritableCellFormat (customDateFormat);
	    dateFormat.setBorder(Border.LEFT, BorderLineStyle.THIN, Colour.BLACK);
	    dateFormat.setBorder(Border.RIGHT, BorderLineStyle.THIN, Colour.BLACK);
	    dateFormat.setBorder(Border.TOP, BorderLineStyle.THIN, Colour.BLACK);
	    dateFormat.setBorder(Border.BOTTOM, BorderLineStyle.THIN, Colour.BLACK);
	    dateFormat.setAlignment(Alignment.RIGHT);
	    dateFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
	    
	    int col = cellStart.getC()+1; 
	    int row = cellStart.getR();
	    
	    FinanceContract[] lines = this.GetLines();
	    
		FinanceContract line2 = new FinanceContract();
		
		line2.Jan = new BigDecimal(0.0);
    	line2.Feb = new BigDecimal(0.0);
    	line2.Mar = new BigDecimal(0.0);
    	line2.Apr = new BigDecimal(0.0);
    	line2.May = new BigDecimal(0.0);
    	line2.Jun = new BigDecimal(0.0);
    	line2.Jul = new BigDecimal(0.0);
    	line2.Aug = new BigDecimal(0.0);
    	line2.Sep = new BigDecimal(0.0);
    	line2.Oct = new BigDecimal(0.0);
    	line2.Nov = new BigDecimal(0.0);
    	line2.Dec = new BigDecimal(0.0);
    	line2.Total1 = new BigDecimal(0.0);
    	
    	line2.Jan1 = new BigDecimal(0.0);
    	line2.Feb1 = new BigDecimal(0.0);
    	line2.Mar1 = new BigDecimal(0.0);
    	line2.Apr1 = new BigDecimal(0.0);
    	line2.May1 = new BigDecimal(0.0);
    	line2.Jun1 = new BigDecimal(0.0);
    	line2.Jul1 = new BigDecimal(0.0);
    	line2.Aug1 = new BigDecimal(0.0);
    	line2.Sep1 = new BigDecimal(0.0);
    	line2.Oct1 = new BigDecimal(0.0);
    	line2.Nov1 = new BigDecimal(0.0);
    	line2.Dec1 = new BigDecimal(0.0);
    	line2.Total2 = new BigDecimal(0.0);
    	
    	line2.Summary = new BigDecimal(0.0);
    	line2.Prepayment = new BigDecimal(0.0);
		
		int j = row;
		
		int buffer = 0;
		
		int counter = row;
		
		for(int i = row; (i-row) < lines.length; i++) {
	    	
			if(!cms_contracts.contains(lines[i-row].CMS_Contract))
				continue;
			
			WriteToExcel(lines[i-row], col,counter+buffer,dateFormat,valuestyle,numcolstyle,sheet,nn);

			buffer += SetLines(col, counter+buffer+1, sheet, lines[i-row].CMS_Contract);
			
			counter++;
			
	    	line2.Jan = line2.Jan.add(lines[i-row].Jan);
	    	line2.Feb = line2.Feb.add(lines[i-row].Feb);
	    	line2.Mar = line2.Mar.add(lines[i-row].Mar);
	    	line2.Apr = line2.Apr.add(lines[i-row].Apr);
	    	line2.May = line2.May.add(lines[i-row].May);
	    	line2.Jun = line2.Jun.add(lines[i-row].Jun);
	    	line2.Jul = line2.Jul.add(lines[i-row].Jul);
	    	line2.Aug = line2.Aug.add(lines[i-row].Aug);
	    	line2.Sep = line2.Sep.add(lines[i-row].Sep);
	    	line2.Oct = line2.Oct.add(lines[i-row].Oct);
	    	line2.Nov = line2.Nov.add(lines[i-row].Nov);
	    	line2.Dec = line2.Dec.add(lines[i-row].Dec);
	    	line2.Total1 = line2.Total1.add(lines[i-row].Total1);
	    	
	    	line2.Jan1 = line2.Jan1.add(lines[i-row].Jan1);
	    	line2.Feb1 = line2.Feb1.add(lines[i-row].Feb1);
	    	line2.Mar1 = line2.Mar1.add(lines[i-row].Mar1);
	    	line2.Apr1 = line2.Apr1.add(lines[i-row].Apr1);
	    	line2.May1 = line2.May1.add(lines[i-row].May1);
	    	line2.Jun1 = line2.Jun1.add(lines[i-row].Jun1);
	    	line2.Jul1 = line2.Jul1.add(lines[i-row].Jul1);
	    	line2.Aug1 = line2.Aug1.add(lines[i-row].Aug1);
	    	line2.Sep1 = line2.Sep1.add(lines[i-row].Sep1);
	    	line2.Oct1 = line2.Oct1.add(lines[i-row].Oct1);
	    	line2.Nov1 = line2.Nov1.add(lines[i-row].Nov1);
	    	line2.Dec1 = line2.Dec1.add(lines[i-row].Dec1);
	    	line2.Total2 = line2.Total2.add(lines[i-row].Total2);
	    	
	    	j++;
	    }
		j += buffer;
		valuestyle = new WritableCellFormat();
		valuestyle.setBorder(Border.LEFT, BorderLineStyle.THIN, Colour.BLACK);
		valuestyle.setBorder(Border.RIGHT, BorderLineStyle.THIN, Colour.BLACK);
		valuestyle.setBorder(Border.BOTTOM, BorderLineStyle.THIN, Colour.BLACK);
		valuestyle.setBorder(Border.TOP, BorderLineStyle.THIN, Colour.BLACK);
		valuestyle.setVerticalAlignment(VerticalAlignment.CENTRE);
		valuestyle.setWrap(true);
		valuestyle.setAlignment(Alignment.RIGHT);
		valuestyle.setBackground(Colour.LIGHT_ORANGE);
		
		numcolstyle = new WritableCellFormat();
		numcolstyle.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK);
		numcolstyle.setAlignment(Alignment.RIGHT);
		numcolstyle.setVerticalAlignment(VerticalAlignment.CENTRE);
		numcolstyle.setWrap(true);
		numcolstyle.setBackground(Colour.LIGHT_ORANGE);
		
		WriteToExcel(line2, col,j,dateFormat,valuestyle,numcolstyle,sheet,nn);
		sheet.mergeCells(col-1, j, col+7, j);		
		sheet.addCell(new Label(col-1,j, "Итого, ежемесячный план, факт", valuestyle));
	    copy.write();
	    copy.close();
	    tableBook.close();
	    temporaryFile.delete();
		indexNum = 0;
		
	    try{    
	   		   String fileName = fullPath.toString();
	   		   String command = "excel \""+fileName+"\"";
	   		   Runtime.getRuntime().exec("cmd /c start "+command);
	   	   }catch(Exception e){
	   		   e.printStackTrace();
	   	   }
			
	   return Msg.translate(m_ctx, "Success");
	}
	
	private int SetLines(int x, int y, WritableSheet sheet, int CMS_Contract_ID) throws SQLException, WriteException
	{	
		// Style for value column
		WritableCellFormat nn = new WritableCellFormat();
		nn.setBorder(Border.LEFT, BorderLineStyle.THIN, Colour.BLACK);
		nn.setBorder(Border.RIGHT, BorderLineStyle.THIN, Colour.BLACK);
		nn.setBorder(Border.BOTTOM, BorderLineStyle.THIN, Colour.BLACK);
		nn.setBorder(Border.TOP, BorderLineStyle.THIN, Colour.BLACK);
		nn.setAlignment(Alignment.CENTRE);
		nn.setVerticalAlignment(VerticalAlignment.CENTRE);
		nn.setWrap(true);
			    
				
		WritableCellFormat valuestyle = new WritableCellFormat();
		valuestyle.setBorder(Border.LEFT, BorderLineStyle.THIN, Colour.BLACK);
		valuestyle.setBorder(Border.RIGHT, BorderLineStyle.THIN, Colour.BLACK);
		valuestyle.setBorder(Border.BOTTOM, BorderLineStyle.THIN, Colour.BLACK);
		valuestyle.setBorder(Border.TOP, BorderLineStyle.THIN, Colour.BLACK);
		valuestyle.setAlignment(Alignment.LEFT);
		valuestyle.setVerticalAlignment(VerticalAlignment.CENTRE);
		valuestyle.setWrap(true);
		// Style for name column
		WritableCellFormat namestyle = new WritableCellFormat();
		namestyle.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK);
		namestyle.setAlignment(Alignment.LEFT);
		namestyle.setVerticalAlignment(VerticalAlignment.CENTRE);
		namestyle.setWrap(true);
		//Style for number column
		WritableCellFormat numcolstyle = new WritableCellFormat();
		numcolstyle.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK);
		numcolstyle.setAlignment(Alignment.RIGHT);
		numcolstyle.setVerticalAlignment(VerticalAlignment.CENTRE);
		numcolstyle.setWrap(true);
		//Style for last number column
		WritableCellFormat lastNumcolstyle = new WritableCellFormat();
		lastNumcolstyle.setBorder(Border.RIGHT, BorderLineStyle.THIN, Colour.BLACK);
		lastNumcolstyle.setBorder(Border.LEFT, BorderLineStyle.THIN, Colour.BLACK);
		lastNumcolstyle.setBorder(Border.TOP, BorderLineStyle.THIN, Colour.BLACK);
		lastNumcolstyle.setBorder(Border.BOTTOM, BorderLineStyle.THIN, Colour.BLACK);
		lastNumcolstyle.setAlignment(Alignment.RIGHT);
		lastNumcolstyle.setVerticalAlignment(VerticalAlignment.CENTRE);
		lastNumcolstyle.setWrap(true);
		//Style for total row
		WritableCellFormat totalrowstyle = new WritableCellFormat();
		totalrowstyle.setBorder(Border.ALL, BorderLineStyle.MEDIUM, Colour.BLACK);
		totalrowstyle.setAlignment(Alignment.RIGHT);
		totalrowstyle.setVerticalAlignment(VerticalAlignment.CENTRE);
		totalrowstyle.setWrap(true);

		DateFormat customDateFormat = new DateFormat ("dd.MM.yy");
		WritableCellFormat dateFormat = new WritableCellFormat (customDateFormat);
		dateFormat.setBorder(Border.LEFT, BorderLineStyle.THIN, Colour.BLACK);
		dateFormat.setBorder(Border.RIGHT, BorderLineStyle.THIN, Colour.BLACK);
		dateFormat.setBorder(Border.TOP, BorderLineStyle.THIN, Colour.BLACK);
		dateFormat.setBorder(Border.BOTTOM, BorderLineStyle.THIN, Colour.BLACK);
		dateFormat.setAlignment(Alignment.RIGHT);
		dateFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
			    
		valuestyle.setBackground(Colour.IVORY);
		numcolstyle.setBackground(Colour.IVORY);
		dateFormat.setBackground(Colour.IVORY);
	    
	    StringBuffer sql = new StringBuffer();
	    sql.append("SELECT b.Name, l.DateSigned, l.Description, l.ContractSummary, l.DateFrom, l.A_Expired_Date, l.BeginningDateExecution, l.EndDateExecution, c.DocumentNo, l.name AS LineDocNo \n");
		sql.append("FROM Adempiere.CMS_ContractLine l LEFT JOIN Adempiere.cms_Contract c on l.CMS_Contract_ID = c.CMS_Contract_ID \n");
		sql.append("LEFT JOIN Adempiere.c_bpartner b on l.C_BPartner_ID = b.C_BPartner_ID \n");
		sql.append("WHERE c.CMS_Contract_ID = " + CMS_Contract_ID);
	
	    PreparedStatement pstmt = null;
	    ResultSet rs = null;
	    
	    Number number;
	    Label label;
	    DateTime time;
	    int index = 0;
	    
	    try
	    {	    	
	    	pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
	 	    rs = pstmt.executeQuery();
	 	    
	    	while(rs.next()){
	    	    
	    		label = new Label(x-1, y, "", valuestyle);  	  
	        	sheet.addCell(label);   
	    		label = new Label(x, y, rs.getString("LineDocNo"), valuestyle);  	  
	        	sheet.addCell(label);   
	        	if(rs.getTimestamp("DateSigned") != null) {
	        		time = new DateTime(x+1, y, new java.sql.Date(rs.getTimestamp("DateSigned").getTime()), dateFormat);
	        		sheet.addCell(time);
	        	}
	        	else {
	        		label = new Label(x+1,y,"", valuestyle);
	        		sheet.addCell(label);
	        	}
	        	
	        	if(rs.getTimestamp("A_Expired_Date") != null) {
	        		time = new DateTime(x+2, y, new java.sql.Date(rs.getTimestamp("A_Expired_Date").getTime()), dateFormat);
	        		sheet.addCell(time);
	        	}
	        	else {
	        		label = new Label(x+2,y,"",valuestyle);
	        		sheet.addCell(label);
	        	}
	        	
	        	label = new Label(x+3,y,rs.getString("Name"), valuestyle);
	        	sheet.addCell(label);
	        	label = new Label(x+4,y,rs.getString("Description"), valuestyle);
	        	sheet.addCell(label);
	        	number = new Number(x+5,y,rs.getDouble("ContractSummary"), numcolstyle);
	        	sheet.addCell(number);
	        	label = new Label(x+6, y, "", valuestyle);
	        	sheet.addCell(label);
	        	label = new Label(x+7, y, "", valuestyle);
	        	sheet.addCell(label);
	        	
	        	for(int i = 0; i < 30; i++)
	        	{
	        		label = new Label(x+8+i, y, "", valuestyle);
	        		sheet.addCell(label);
	        	}
	        	y++;
	        	index++;
	    	}
	    }
	    catch (Exception e)
	    {
	    	log.log(Level.SEVERE, "CMS_FinanceContractReport: " + e.toString());
	    }
		finally
		{
			DB.close(rs, pstmt);
			rs = null; pstmt = null;
		}
	    
	    return index;	    
	}
	
	private void WriteToExcel(FinanceContract contract, int col, int i, WritableCellFormat dateFormat, WritableCellFormat valuestyle, WritableCellFormat numcolstyle, WritableSheet sheet, WritableCellFormat nn) throws RowsExceededException, WriteException
	{
		indexNum++;
    	
		Number number;
		Label label;
		DateTime time;
		
		WritableCellFormat docNumStyle = new WritableCellFormat();
		docNumStyle.setBorder(Border.LEFT, BorderLineStyle.THIN, Colour.BLACK);
		docNumStyle.setBorder(Border.RIGHT, BorderLineStyle.THIN, Colour.BLACK);
		docNumStyle.setBorder(Border.BOTTOM, BorderLineStyle.THIN, Colour.BLACK);
		docNumStyle.setBorder(Border.TOP, BorderLineStyle.THIN, Colour.BLACK);
		docNumStyle.setAlignment(Alignment.CENTRE);
	    docNumStyle.setVerticalAlignment(VerticalAlignment.CENTRE);
	    docNumStyle.setWrap(true);
	    
		number = new Number(col-1, i, indexNum, nn);  	  
    	sheet.addCell(number);   
    	label = new Label(col, i, contract.ContractNum, docNumStyle);        
    	sheet.addCell(label);
    	if(contract.ContractDate != null) {
    		time = new DateTime(col+1, i, new java.sql.Date(contract.ContractDate.getTime()), dateFormat);     
    		sheet.addCell(time);
    	}
    	else {
    		label = new Label(col+1, i, "", valuestyle);
    	    sheet.addCell(label);
    	}
    	
    	if(contract.ExpiredDate != null) {
    		time = new DateTime(col+2, i, new java.sql.Date(contract.ExpiredDate.getTime()), dateFormat);     
    		sheet.addCell(time);
    	}
    	else {
    		label = new Label(col+2, i, "", valuestyle);
    	    sheet.addCell(label);
    	}
    	
    	if(contract.Summary == null)
    		contract.Summary = new BigDecimal(0.0);
    	
    	label = new Label(col+3, i, contract.BPartner, valuestyle);     
    	sheet.addCell(label);    	   
    	label = new Label(col+4, i, contract.Description, valuestyle);     
    	sheet.addCell(label); 
    	number = new Number(col+5, i, contract.Summary.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number); 
    	label = new Label(col+6, i, contract.Prepayment + "%", docNumStyle);     
    	sheet.addCell(label); 
    	label = new Label(col+7, i, contract.Combined, valuestyle);     
    	sheet.addCell(label); 
    	label = new Label(col+8, i, "", valuestyle);     
    	sheet.addCell(label);   	   
    	number = new Number(col+9, i, contract.Jan.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);   	  
    	number = new Number(col+10, i, contract.Feb.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);   
    	number = new Number(col+11, i, contract.Mar.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+12, i, contract.Apr.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+13, i, contract.May.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+14, i, contract.Jun.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+15, i, contract.Jul.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+16, i, contract.Aug.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+17, i, contract.Sep.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+18, i, contract.Oct.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+19, i, contract.Nov.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+20, i, contract.Dec.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+21, i, contract.Total1.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	label = new Label(col+22, i, "", valuestyle);
    	sheet.addCell(label);
    	number = new Number(col+23, i, contract.Jan1.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+24, i, contract.Feb1.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+25, i, contract.Mar1.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+26, i, contract.Apr1.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+27, i, contract.May1.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+28, i, contract.Jun1.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+29, i, contract.Jul1.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+30, i, contract.Aug1.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+31, i, contract.Sep1.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+32, i, contract.Oct1.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+33, i, contract.Nov1.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+34, i, contract.Dec1.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	number = new Number(col+35, i, contract.Total2.setScale(2, RoundingMode.HALF_UP).doubleValue(), numcolstyle);     
    	sheet.addCell(number);
    	label = new Label(col+36, i, "", valuestyle);
    	sheet.addCell(label);
    	label = new Label(col+37, i, "", valuestyle);
    	sheet.addCell(label);
	}
	
	private FinanceContract[] GetLines() throws Exception {
		FinanceContract temp = null;
		List<FinanceContract> list = new ArrayList<FinanceContract>();
		
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		Date date = null;
		
		
		if(DateFrom != null)		
			date = new java.sql.Date(DateFrom.getTime());
		else
		{
			Calendar currentDate = Calendar.getInstance();
			java.util.Date date2 = currentDate.getTime();
			date = new java.sql.Date(date2.getTime());
		}
		
		String query = "SELECT cms_contractstype_id FROM cms_contractstype WHERE lower(name) like 'доход%'";
		
		int cms_contractstype_id = 0;
		
		cms_contractstype_id = DB.getSQLValue(get_TrxName(), query);
		if(cms_contractstype_id == -1)
		{
			log.info("Не найдено значение 'Доходный' договор в справочнике cms_contractstype");
			throw new Exception();
		}
		
		StringBuffer sqlQuery = new StringBuffer();
		sqlQuery.append("SELECT c.CMS_Contract_ContractNum, c.CMS_Contract_CreatDate, c.A_Expired_Date, b.Name, c.description, c.ContractSummary, c.Prepayment, c.PaymentTerms || ' ' || p.Name AS CombinedCol, \n");
		sqlQuery.append("(SELECT SUM(g1.PaymentSum) FROM Adempiere.CMS_Payment g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.01.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.01.31', 'yyyy-mm-dd')) AS Jan, \n");
		sqlQuery.append("(SELECT SUM(g1.PaymentSum) FROM Adempiere.CMS_Payment g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.02.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.02.28', 'yyyy-mm-dd')) AS Feb, \n"); 
		sqlQuery.append("(SELECT SUM(g1.PaymentSum) FROM Adempiere.CMS_Payment g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.03.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.03.31', 'yyyy-mm-dd')) AS Mar, \n"); 
		sqlQuery.append("(SELECT SUM(g1.PaymentSum) FROM Adempiere.CMS_Payment g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.04.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.04.30', 'yyyy-mm-dd')) AS Apr, \n"); 
		sqlQuery.append("(SELECT SUM(g1.PaymentSum) FROM Adempiere.CMS_Payment g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.05.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.05.31', 'yyyy-mm-dd')) AS May, \n"); 
		sqlQuery.append("(SELECT SUM(g1.PaymentSum) FROM Adempiere.CMS_Payment g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.06.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.06.30', 'yyyy-mm-dd')) AS Jun, \n"); 
		sqlQuery.append("(SELECT SUM(g1.PaymentSum) FROM Adempiere.CMS_Payment g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.07.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.07.31', 'yyyy-mm-dd')) AS Jul, \n"); 
		sqlQuery.append("(SELECT SUM(g1.PaymentSum) FROM Adempiere.CMS_Payment g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.08.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.08.31', 'yyyy-mm-dd')) AS Aug, \n"); 
		sqlQuery.append("(SELECT SUM(g1.PaymentSum) FROM Adempiere.CMS_Payment g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.09.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.09.30', 'yyyy-mm-dd')) AS Sep, \n"); 
		sqlQuery.append("(SELECT SUM(g1.PaymentSum) FROM Adempiere.CMS_Payment g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.10.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.10.31', 'yyyy-mm-dd')) AS Oct, \n"); 
		sqlQuery.append("(SELECT SUM(g1.PaymentSum) FROM Adempiere.CMS_Payment g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.11.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.11.30', 'yyyy-mm-dd')) AS Nov, \n"); 
		sqlQuery.append("(SELECT SUM(g1.PaymentSum) FROM Adempiere.CMS_Payment g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.12.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.12.31', 'yyyy-mm-dd')) AS Dec, \n"); 
		sqlQuery.append("(SELECT SUM(g1.PaymentSum) FROM Adempiere.CMS_Payment g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.01.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.12.31', 'yyyy-mm-dd')) AS TotalSum, \n"); 
		sqlQuery.append("(SELECT SUM(g1.SupplySum) FROM Adempiere.CMS_Supplies g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.01.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.01.31', 'yyyy-mm-dd')) AS Jan1, \n");
		sqlQuery.append("(SELECT SUM(g1.SupplySum) FROM Adempiere.CMS_Supplies g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.02.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.02.28', 'yyyy-mm-dd')) AS Feb1, \n"); 
		sqlQuery.append("(SELECT SUM(g1.SupplySum) FROM Adempiere.CMS_Supplies g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.03.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.03.31', 'yyyy-mm-dd')) AS Mar1, \n"); 
		sqlQuery.append("(SELECT SUM(g1.SupplySum) FROM Adempiere.CMS_Supplies g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.04.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.04.30', 'yyyy-mm-dd')) AS Apr1, \n"); 
		sqlQuery.append("(SELECT SUM(g1.SupplySum) FROM Adempiere.CMS_Supplies g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.05.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.05.31', 'yyyy-mm-dd')) AS May1, \n"); 
		sqlQuery.append("(SELECT SUM(g1.SupplySum) FROM Adempiere.CMS_Supplies g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.06.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.06.30', 'yyyy-mm-dd')) AS Jun1, \n"); 
		sqlQuery.append("(SELECT SUM(g1.SupplySum) FROM Adempiere.CMS_Supplies g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.07.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.07.31', 'yyyy-mm-dd')) AS Jul1, \n"); 
		sqlQuery.append("(SELECT SUM(g1.SupplySum) FROM Adempiere.CMS_Supplies g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.08.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.08.31', 'yyyy-mm-dd')) AS Aug1, \n"); 
		sqlQuery.append("(SELECT SUM(g1.SupplySum) FROM Adempiere.CMS_Supplies g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.09.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.09.30', 'yyyy-mm-dd')) AS Sep1, \n"); 
		sqlQuery.append("(SELECT SUM(g1.SupplySum) FROM Adempiere.CMS_Supplies g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.10.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.10.31', 'yyyy-mm-dd')) AS Oct1, \n"); 
		sqlQuery.append("(SELECT SUM(g1.SupplySum) FROM Adempiere.CMS_Supplies g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.11.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.11.30', 'yyyy-mm-dd')) AS Nov1, \n"); 
		sqlQuery.append("(SELECT SUM(g1.SupplySum) FROM Adempiere.CMS_Supplies g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.12.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.12.31', 'yyyy-mm-dd')) AS Dec1, \n"); 
		sqlQuery.append("(SELECT SUM(g1.SupplySum) FROM Adempiere.CMS_Supplies g1 WHERE g1.CMS_Contract_ID = c.CMS_Contract_ID AND g1.DateAcct BETWEEN To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.01.01','yyyy-mm-dd') AND To_Date(EXTRACT(year FROM TIMESTAMP '" + date.toString() + "') || '.12.31', 'yyyy-mm-dd')) AS TotalSum1, \n");
		sqlQuery.append("c.CMS_Contract_ID \n");
		sqlQuery.append("FROM Adempiere.CMS_Contract c LEFT JOIN Adempiere.CMS_PrepaymentType p ON c.CMS_PrepaymentType_ID = p.CMS_PrepaymentType_ID LEFT JOIN Adempiere.C_BPartner b ON c.C_BPartner_ID = b.C_BPartner_ID \n");
		sqlQuery.append("WHERE c.AD_Client_ID = ? AND c.AD_Org_ID = ? AND CMS_ContractsType_ID = " + cms_contractstype_id);
		
		if(C_BPartner_ID != 0)
			sqlQuery.append(" AND c.C_BPartner_ID =" + C_BPartner_ID);
		
		if(DateFrom != null)
			sqlQuery.append(" AND c.CMS_Contract_CreatDate >= '" + DateFrom + "'");
		if(DateTo != null)
			sqlQuery.append("AND c.CMS_Contract_CreatDate <= '" + DateTo + "'");
		
		sqlQuery.append(" order by c.CMS_Contract_ContractNum");
		
		try{
			pstmt = DB.prepareStatement(sqlQuery.toString(), get_TrxName());
			pstmt.setInt(1, AD_Client_ID);
			pstmt.setInt(2, AD_Org_ID);
			rs = pstmt.executeQuery();
			
			while(rs.next())
			{
				temp = new FinanceContract();
				temp.ContractNum = rs.getString(1);
				temp.ContractDate = rs.getTimestamp(2);
				temp.ExpiredDate = rs.getTimestamp(3);
				temp.BPartner = rs.getString(4);
				temp.Description = rs.getString(5);
				temp.Summary = getBack(rs.getBigDecimal(6));
				temp.Prepayment = getBack(rs.getBigDecimal(7));
				temp.Combined = rs.getString(8);
				
				temp.Jan = getBack(rs.getBigDecimal(9));
				temp.Feb = getBack(rs.getBigDecimal(10));
				temp.Mar = getBack(rs.getBigDecimal(11));
				temp.Apr = getBack(rs.getBigDecimal(12));
				temp.May = getBack(rs.getBigDecimal(13));
				temp.Jun = getBack(rs.getBigDecimal(14));
				temp.Jul = getBack(rs.getBigDecimal(15));
				temp.Aug = getBack(rs.getBigDecimal(16));
				temp.Sep = getBack(rs.getBigDecimal(17));
				temp.Oct = getBack(rs.getBigDecimal(18));
				temp.Nov = getBack(rs.getBigDecimal(19));
				temp.Dec = getBack(rs.getBigDecimal(20));
				temp.Total1 = getBack(rs.getBigDecimal(21));
				temp.Jan1 = getBack(rs.getBigDecimal(22));
				temp.Feb1 = getBack(rs.getBigDecimal(23));
				temp.Mar1 = getBack(rs.getBigDecimal(24));
				temp.Apr1 = getBack(rs.getBigDecimal(25));
				temp.May1 = getBack(rs.getBigDecimal(26));
				temp.Jun1 = getBack(rs.getBigDecimal(27));
				temp.Jul1 = getBack(rs.getBigDecimal(28));
				temp.Aug1 = getBack(rs.getBigDecimal(29));
				temp.Sep1 = getBack(rs.getBigDecimal(30));
				temp.Oct1 = getBack(rs.getBigDecimal(31));
				temp.Nov1 = getBack(rs.getBigDecimal(32));
				temp.Dec1 = getBack(rs.getBigDecimal(33));			
				temp.Total2 = getBack(rs.getBigDecimal(34));
				temp.CMS_Contract = rs.getInt(35);
				list.add(temp);
			}
		}
		catch(Exception e)
		{
			s_log.log(Level.SEVERE, "CMS_FinanceContractReport ", e);
		}
		finally
		{
			DB.close(rs, pstmt);
			rs = null; pstmt = null;
		}
		
		return list.toArray(new FinanceContract[list.size()]);
	}
	
	private ArrayList<Integer> cms_contracts = new ArrayList<Integer>();
	
	@SuppressWarnings("deprecation")
	private int getCMS_Contract_ID()
	{
		StringBuffer sql = new StringBuffer();
		
		sql.append("SELECT cms_roleaccess(");
		sql.append(AD_User_ID + ", ");
		sql.append(AD_Role_ID + ")");
		
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		try
		{
			pstmt = DB.prepareStatement(sql.toString());
			rs = pstmt.executeQuery();
			
			while(rs.next())
			{
				cms_contracts.add(rs.getInt(1));
			}
		}
		catch(Exception e)
		{
			s_log.log(Level.SEVERE, e.toString());
		}
		finally
		{
			try {rs.close(); pstmt.close();}
			catch(Exception e){}
		}
		
		return cms_contracts.size();
	}
	
	private BigDecimal getBack(BigDecimal dec)
	{
		return dec == null ? new BigDecimal(0.0) : dec;
	}
	
	public class FinanceContract {
		public FinanceContract(){}
		
		public String ContractNum;
		public Timestamp ContractDate;
		public Timestamp ExpiredDate;
		public String BPartner;
		public String Description;
		public BigDecimal Summary;
		public BigDecimal Prepayment;
		public String Combined;
		
		public BigDecimal Jan;
		public BigDecimal Feb;
		public BigDecimal Mar;
		public BigDecimal Apr;
		public BigDecimal May;
		public BigDecimal Jun;
		public BigDecimal Jul;
		public BigDecimal Aug;
		public BigDecimal Sep;
		public BigDecimal Oct;
		public BigDecimal Nov;
		public BigDecimal Dec;
		public BigDecimal Total1;
		
		public BigDecimal Jan1;
		public BigDecimal Feb1;
		public BigDecimal Mar1;
		public BigDecimal Apr1;
		public BigDecimal May1;
		public BigDecimal Jun1;
		public BigDecimal Jul1;
		public BigDecimal Aug1;
		public BigDecimal Sep1;
		public BigDecimal Oct1;
		public BigDecimal Nov1;
		public BigDecimal Dec1;
		public BigDecimal Total2;
		
		public int CMS_Contract;
	}
}
